#lang scheme

(define read-file-content
  (lambda (strm)
    (let ((s (read-line strm)))
      (if (eof-object? s)
          '()
          (cons (read (open-input-string (string-append "(" s ")")))
                (read-file-content strm)))))) 

(define trapezoid-area
  (lambda (pa pb)
    (let ((xa (car pa)) (ya (cadr pa))
          (xb (car pb)) (yb (cadr pb)))
      (* (- xb xa) (/ (+ ya yb) 2.0)))))
                      
(define area-under-plot
  (lambda (pairs)
    (if (< (length pairs) 2)
        0
        (+ (trapezoid-area (car pairs) (cadr pairs))
           (area-under-plot (cdr pairs))))))


(area-under-plot
 (read-file-content
  (open-input-file
   "D:/Projects/code-storage-my/lisp/test1.txt")))


